const express = require('express')
const mongoose = require('mongoose')
const app = express()
const passport = require('passport')
const port = process.env.PORT || 3000

//引入user.js
const user = require("./router/api/user")
    //引入profile.js
const profile = require("./router/api/profile")
    //DB config
const db = require("./config/keys").mongoURL

//等同于使用body-parser中间件
app.use(express.urlencoded({ extended: false }))
app.use(express.json())

//连接数据库
mongoose.connect(db)
    .then(() => console.log("Mongoose连接成功"))
    .catch(err => console.log(err))

//passport初始化
app.use(passport.initialize());
require('./config/passport')(passport);
//使用router
app.use("/api/user", user)
app.use("/api/profile", profile)
app.listen(port, () => console.log(`Example app listening on port port!${port}`))